package com.zhibi.util.codec;


import java.io.UnsupportedEncodingException;

import com.zhibi.util.codec.aes.AESUtil;
import com.zhibi.util.codec.base64.BASE64Util;
import com.zhibi.util.codec.common.DigestUtil;
import com.zhibi.util.codec.rsa.RSAUtil;

/**
 * 加解密的综合工具类
 *
 */
public class CodecUtil {

	/**
	 * AES 加密
	 * @param content
	 * @param key
	 * @return
	 */
	public static String AESEncrypt(String content,String key){
		return AESUtil.encrypt(content, key,null);
	}

	/**
	 * AES 加密
	 * @param content
	 * @param key
	 * @param charset 
	 * @return
	 */
	public static String AESEncrypt(String content,String key,String charset){
		return AESUtil.encrypt(content, key,charset);
	}

	/**
	 * AES 解密
	 * @param content
	 * @param key
	 * @return
	 */
	public static String AESDecrypt(String content,String key){
		return AESUtil.decrypt(content, key,null);
	}

	/**
	 * AES 解密
	 * @param content
	 * @param key
	 * @param charset
	 * @return
	 */
	public static String AESDecrypt(String content,String key,String charset){
		return AESUtil.decrypt(content, key,charset);
	}

	/**
	 * base64  加密
	 * @param content
	 * @return
	 */
	public static String BASE64Encrypt(String content){
		try {
			return BASE64Util.encrypt(content, null);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * base64  加密
	 * @param content
	 * @param charset
	 * @return
	 */
	public static String BASE64Encrypt(String content,String charset){
		try {
			return BASE64Util.encrypt(content, charset);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * base64  解密
	 * @param content
	 * @return
	 */
	public static String BASE64Decrypt(String content){
		try {
			return BASE64Util.decrypt(content, null);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * base64  解密
	 * @param content
	 * @param charset
	 * @return
	 */
	public static String BASE64Decrypt(String content,String charset){
		try {
			return BASE64Util.decrypt(content, charset);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * RSA 加密
	 * @param publicKey
	 * @param content
	 * @param charset
	 * @return
	 */
	public static String RSAEncrypt(String publicKey,String content,String charset){
		return RSAUtil.encrypt(publicKey, content, charset);
	}
	
	/**
	 * RSA 加密
	 * @param publicKey
	 * @param content
	 * @return
	 */
	public static String RSAEncrypt(String publicKey,String content){
		return RSAUtil.encrypt(publicKey, content, null);
	}
	
	/**
	 * RSA 解密
	 * @param publicKey
	 * @param content
	 * @return
	 */
	public static String RSADecrypt(String publicKey,String content){
		return RSAUtil.decrypt(publicKey, content, null);
	}
	
	/**
	 * RSA 解密
	 * @param publicKey
	 * @param content
	 * @param charset
	 * @return
	 */
	public static String RSADecrypt(String publicKey,String content,String charset){
		return RSAUtil.decrypt(publicKey, content, charset);
	}
	
	/**
	 * SHA256 摘要
	 * @param content
	 * @return
	 */
	public static String SHA256Digest(String content){
		return DigestUtil.SHA256(content);
	}
	
	/**
	 * SHA1 摘要
	 * @param content
	 * @return
	 */
	public static String SHA1Digest(String content){
		return DigestUtil.SHA1(content);
	}
	
	/**
	 * SHA 摘要
	 * @param content
	 * @return
	 */
	public static String SHADigest(String content){
		return DigestUtil.SHA(content);
	}
	
	/**
	 * MD5 摘要
	 * @param content
	 * @return
	 */
	public static String MD5Digest(String content){
		return DigestUtil.MD5(content);
	}
}
